package scalaLearning.part3

import scala.util.Random

object CaseDemo {
  def main(args: Array[String]): Unit = {
    //值的匹配
    val arr = Array("Tom", "Susan", "Jim")
    val i = Random.nextInt(arr.length)
    val name = arr(i)
    name match {
      case "Tom" => println("汤姆")
      case "Susan" => println("苏珊")
      case _ => println("我不认识")
    }
    //类型的匹配
    val arr2 = Array(1, "susan", true, 2L)
    val j = Random.nextInt(arr2.length)
    val name2 = arr2(j)
    name2 match {
      case x: Int => println("Int")
      case y: String => println("string")
      case z: Boolean => println("Boolean")
      case _ => println("我不知道的类型")
    }
    //数组的匹配
    val arr3 = Array("aa", "bb", 123)
    arr3 match {
      case Array(x, 123, 123) => println("aa")
      case Array(_, x, _) => println(x)

    }

  }
}
